package cn.myjerry.others.guava;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
/**
 * 分析查看每个教师所教授的课程
 * Multimap： key-->value key可以重复
 * @author zpon
 *
 */
public class Demo06 {
	public static void main(String[] args) {
		Map<String, String> map = new HashMap<>();
		map.put("数学", "小王");
		map.put("英语", "小李");
		map.put("语文", "小李");
		map.put("物理", "小赵");
		map.put("化学", "小赵");
		map.put("生物", "小王");
		
		Multimap<String, String> teachers = ArrayListMultimap.create();
		
		Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
		while(it.hasNext()) {
			Map.Entry<String, String> entry = it.next();
			String key = entry.getKey();
			String value = entry.getValue();
			
			teachers.put(value, key);
		}
		
		Set<String> keySet = teachers.keySet();
		for(String key:keySet) {
			Collection<String> col = teachers.get(key);
			System.out.println(key + "==>" + col);
		}
	}
}
